unit con_Motivo_CobBanco;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls,
  TFlatButtonUnit, Buttons, ExtCtrls, DB, DBTables;

type
  TfrmCon_Motivo_CobBanco = class(TFrmConsulta)
    Label1: TLabel;
    edtNome: TEdit;
    dbgBanco: TDBGrid;
    Query1: TQuery;
    procedure edtNomeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    cod_layout, cod_Ocorrencia, cod_Motivo: string;
  end;

var
  frmCon_Motivo_CobBanco: TfrmCon_Motivo_CobBanco;

implementation

uses clsMotivo, Dm, Biblio;

var
  tds: Tdatasource;
  tq: Tquery;
  Motivo: TMotivo;

{$R *.dfm}

  { TFrmConsulta1 }

procedure TfrmCon_Motivo_CobBanco.FazConsulta;
begin
  if edtnome.text = '' then edtnome.text := ' ';
  Motivo.Consultar(tq, cod_Layout,cod_Ocorrencia, edtnome.text);
end;

procedure TfrmCon_Motivo_CobBanco.edtNomeKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if key = 12 then FazConsulta;
end;

procedure TfrmCon_Motivo_CobBanco.FormActivate(Sender: TObject);
begin
  inherited;
  Motivo:= TMOTIVO.Create;
  tds := TDataSource.create(self);
  tq := Tquery.create(self);
  tq.databasename := dmint.db.databasename;
  tds.DataSet := tq;
  dbgBanco.DataSource := tds;
  fazconsulta;
  edtnome.setfocus;
end;

procedure TfrmCon_Motivo_CobBanco.BtnFecharClick(Sender: TObject);
begin
  cod_Layout := tq.fieldbyname('ID_LAYOUT').asstring;
  cod_Ocorrencia:=tq.fieldbyname('ID_OCORRENCIA').asstring;
  cod_motivo:= tq.FieldByName('ID_MOTIVO').AsString;
  inherited;
end;

procedure TfrmCon_Motivo_CobBanco.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Motivo.free;
  tds.free;
  tq.free;
end;

end.

